package com.ruoyi.web.controller.record;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.web.domain.ReservationFail;
import com.ruoyi.web.service.IReservationFailService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约失败Controller
 * 
 * @author ruoyi
 * @date 2023-11-02
 */
@Controller
@RequestMapping("/execution/fail")
public class ReservationFailController extends BaseController
{
    private String prefix = "execution/fail";

    @Autowired
    private IReservationFailService reservationFailService;

    @GetMapping()
    public String fail()
    {
        return prefix + "/fail";
    }

    /**
     * 查询预约失败列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReservationFail reservationFail)
    {
        startPage();
        reservationFail.setCreateBy(ShiroUtils.getSysUser().getLoginName());
        List<ReservationFail> list = reservationFailService.selectReservationFailList(reservationFail);
        return getDataTable(list);
    }

    /**
     * 导出预约失败列表
     */
    @Log(title = "预约失败", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReservationFail reservationFail)
    {
        List<ReservationFail> list = reservationFailService.selectReservationFailList(reservationFail);
        ExcelUtil<ReservationFail> util = new ExcelUtil<ReservationFail>(ReservationFail.class);
        return util.exportExcel(list, "预约失败数据");
    }

    /**
     * 新增预约失败
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存预约失败
     */
    @Log(title = "预约失败", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReservationFail reservationFail)
    {
        return toAjax(reservationFailService.insertReservationFail(reservationFail));
    }

    /**
     * 修改预约失败
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ReservationFail reservationFail = reservationFailService.selectReservationFailById(id);
        mmap.put("reservationFail", reservationFail);
        return prefix + "/edit";
    }

    /**
     * 修改保存预约失败
     */
    @Log(title = "预约失败", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReservationFail reservationFail)
    {
        return toAjax(reservationFailService.updateReservationFail(reservationFail));
    }

    /**
     * 删除预约失败
     */
    @Log(title = "预约失败", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(reservationFailService.deleteReservationFailByIds(ids));
    }
}
